<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="include-head.jsp"%>
<%@include file="include-nav.jsp"%>
<%@include file="include-sidebar.jsp"%>

<link rel="stylesheet" type="text/css" href="/static/css/pagination01.css"/>



<html class="container-fluid">
    <div class="row">
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">

                    <form method="post" action="/admin/query/for/search" class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input
                                        value="${param.keyword}"
                                        name="keyword"
                                        class="form-control has-success" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询</button>
                    </form>

                    <button
                            id="batchRemoveBtn"
                            type="button" class="btn btn-danger"
                            style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove">
                    </i> 删除</button>
                    <button type="button" class="btn btn-primary" style="float:right;"
                            onclick="window.location.href='add.html'">
                        <i class="glyphicon glyphicon-plus"></i> 新增</button>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr >
                                <th width="30">#</th>
                                <th width="30"><input type="checkbox" id="summaryBox"></th>
                                <th>账号</th>
                                <th>名称</th>
                                <th>邮箱地址</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                                           <%--进行判断 requestScope['PAGE_INFO'].list}   如果为空则输出这个--%>
                            <c:if test="${empty requestScope['PAGE-INFO'].list}">
                                <tr><%--不能为下滑线  会报错--%>
                                    <td style="text-align: center;" colspan="6">
                                        抱歉！没有符合您要求的查询结果！</td>
                                </tr>
                            </c:if>
                                           <%--进行判断不为空的话 则输出查询出来的值--%>
                            <c:if test="${!empty requestScope['PAGE-INFO'].list}">
                           <c:forEach var="admin" items="${requestScope['PAGE-INFO'].list}" varStatus="myStatus">
                               <tr>
                                   <td>${myStatus.count}</td>
                                   <td><input adminId="${admin.id}" type="checkbox"  class="itemBox"></td>
                                   <td>${admin.loginacct}</td>
                                   <td>${admin.username}</td>
                                   <td>${admin.email}</td>
                                   <td>
                                   <td>
                                       <button type="button" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></button>
                                       <button type="button" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></button>
                                       <button type="button" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></button>
                                   </td>
                               </tr>

                           </c:forEach>
                            </c:if>
                            </tbody>
                            <tfoot>
                            <tr >
                                <td colspan="6" align="center">
                                    <div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
    </div>
</div>
<script src="jquery/jquery-2.1.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="script/docs.min.js"></script>
<script src="script/jquery.pagination.js" type="text/javascript"></script>

<script type="text/javascript" >

    $(function () {
        $(".list-group-item").click(function(){
            if ( $(this).find("ul") ) {
                $(this).toggleClass("tree-closed");
                if ( $(this).hasClass("tree-closed") ) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        initPagination();
    });

    // 声明函数封装导航条初始化操作
    function initPagination() {
        // 声明变量存储总记录数
        var totalRecord = ${requestScope['PAGE-INFO'].total};
        // 声明变量存储分页导航条显示时的属性设置
        var paginationProperties = {
            num_edge_entries : 3,        //边缘页数
            num_display_entries : 5,      //主体页数
            callback : pageselectCallback, //回调函数
            items_per_page : ${requestScope['PAGE-INFO'].pageSize},    //每页显示数据数量，就是pageSize
            current_page : ${requestScope['PAGE-INFO'].pageNum - 1},//当前页页码
            prev_text : "上一页",       //上一页文本
            next_text : "下一页"        //下一页文本
        };
        // 显示分页导航条
        $("#Pagination").pagination(totalRecord, paginationProperties);

       // /!*实现全选全部选的功能*!/
        $("#summaryBox").click(function() {
            // 获取当前#summaryBox的勾选状态
            // this代表当前多选框对象（DOM对象）
            // checked属性为true时表示被勾选，为false时表示没有被勾选
            // 使用checkStatus设置.itemBox的状态
          //  /!*attr  是 有缓存   prop  是刚刚写的 修改状态*!/
            $(".itemBox").prop("checked",this.checked);
        })


        /*/!*获取 要删除的 本行数据的id 给本行数据加上id*!/*/
        $("#batchRemoveBtn").click(function () {
            // 创建数组对象：存储adminId
            var adminIdArray = new Array();
            $(".itemBox:checked").each(function () {
                var adminId=$(this).attr("adminId");
                adminIdArray.push(adminId);
            })
            alert(adminIdArray);
    }

    // 在每一次点击“上一页”、“下一页”、“页码”时执行这个函数跳转页面
    function pageselectCallback(pageIndex, jq) {
        // pageIndex从0开始，pageNum从1开始
        var pageNum = pageIndex + 1;
        //使用属性选择器 要加[]
        var keyword=$('[name="keyword"]').val();
        // 跳转页面
        window.location.href = "/admin/query/for/search?pageNum="+pageNum+"&keyword=${param.keyword}";
        return false;
    }

    }




</script>
</body>
</html>